package com.xnxy.design.action;


import com.xnxy.design.util.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

@Controller
public class RedisTestController {

    @Autowired
    private RedisUtils redisUtils;


    @RequestMapping("/test/{id}")
    @ResponseBody
    public String test(HttpServletRequest request, HttpServletResponse response, @PathVariable String id) throws IOException {

//        TimeUnit.DAYS          天
//        TimeUnit.HOURS         小时
//        TimeUnit.MINUTES       分钟
//        TimeUnit.SECONDS       秒
//        TimeUnit.MILLISECONDS  毫秒

        redisUtils.set("id", "test", (long) 10, TimeUnit.SECONDS);
        System.out.println(redisUtils.get("id"));
        return (String) redisUtils.get("id");
    }
}
